package com.kadron.home;

import java.io.Serializable;

import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import com.kadron.application.KApplicationModel;
import com.kadron.common.KConst;
import com.kadron.creator.KApplicationModelCreator;
import com.kadron.dao.KApplicationDAO;
import com.kadron.dao.KEmbedDAO;
import com.kadron.dao.KImageDAO;
import com.kadron.dao.KNewsDAO;
import com.kadron.datamodel.KDataModel;
import com.kadron.datamodel.KNewsModelDataProvider;
import com.kadron.entity.Embed;
import com.kadron.manager.KMessageManager;
import com.kadron.manager.KSelection;

@AutoCreate
@Scope(ScopeType.PAGE)
@Name("kHome")
public class KHome extends KMessageManager implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2066556966063117603L;

	private KApplicationModel am;
	private Embed embed;
	private KDataModel newsList;
	private KNewsModelDataProvider dataProvider;
	
	@In
	private KNewsDAO newsDAO;
	@In
	private KImageDAO imageDAO;
	@In
	private KApplicationDAO applicationDAO;
	@In
	private KEmbedDAO embedDAO;
	
	@Create
	public void init() {
		dataProvider = new KNewsModelDataProvider(null, newsDAO);
		newsList = new KDataModel(dataProvider);
		KApplicationModelCreator creator = new KApplicationModelCreator(imageDAO, applicationDAO);
		am = creator.getNew();
		embed = embedDAO.getNew();
	}

	public KDataModel getNewsList() {
		return newsList;
	}
	
	public KApplicationModel getAm() {
		return am;
	}

	public Embed getEmbed() {
		return embed;
	}

	public String viewNews(Long newsId) {
		if (newsId == null) {
			bad(KConst.BAD_THING);
			return null;
		}
		KSelection kselection = (KSelection) Component.getInstance("kSelection");
		kselection.setItemId(newsId);
		return "k_news";
	}
	
}
